package model

import (
	"chat_08_21/global"
	"gorm.io/gorm"
	"time"
)

type User struct {
	Id         uint32         `gorm:"column:id;type:int UNSIGNED;comment:用户ID;primaryKey;not null;" form:"id" json:"id"`  // 用户ID
	Mobile     string         `gorm:"column:mobile;type:char(11);comment:手机号;not null;" form:"mobile" json:"mobile"`      // 手机号
	Password   string         `gorm:"column:password;type:char(32);comment:密码;not null;" form:"password" json:"password"` // 密码
	CreatedAtd time.Time      `gorm:"column:created_atd;type:datetime(3);not null;default:CURRENT_TIMESTAMP(3);" form:"created_atd" json:"created_atd"`
	UpdatedAt  time.Time      `gorm:"column:updated_at;type:datetime(3);not null;default:CURRENT_TIMESTAMP(3);" form:"updated_at" json:"updated_at"`
	DeletedAt  gorm.DeletedAt `gorm:"column:deleted_at;type:datetime(3);default:NULL;" form:"deleted_at" json:"deleted_at"`
}

func (u *User) TableName() string {
	return "user"
}

func (u *User) RegisterUser() error {
	return global.DB.Create(&u).Error
}

func (u *User) LoginUser() error {
	return global.DB.Where("mobile = ?", u.Mobile).Find(&u).Error
}
